<?php

namespace app\controllers;

use yii\web\Controller;
use yii\data\Pagination;
use app\models\Info_information;

class BasicServiceController extends Controller
{
    //禁用原有布局
    public $layout="main2";
    //线下活动
    public function actionShowActivity()
    {
        RegisterController::prepare();
        $informations = $this->getInfomation('activity');
            return $this->render('activity',[
                'informations' => $informations
                ]);
    }
    //创业资讯
    public function actionShowInformation()
    {
        RegisterController::prepare();
        $informations = $this->getInfomation('information');
            return $this->render('information',[
                'informations' => $informations
                ]);
    }
    //工商注册
    public function actionShowBusiness()
    {
        RegisterController::prepare();
        return $this->render('business');
    }
    //财务代办
    public function actionShowFinance()
    {
        RegisterController::prepare();
        return $this->render('finance');
    }
    //法务咨询
    public function actionShowLaw()
    {
        RegisterController::prepare();
        return $this->render('law');
    }
    //资讯数据
    public function getInfomation($type)
    {   
        //线下活动部分
        if($type == 'activity')
        {
            $query = Info_information::find()
            ->where([
                'del_flag' => 0,
                    'type' => 0 //0代表活动
                    ]);
        }
        //创业资讯部分 
        else if($type == 'information')
        {
            $query = Info_information::find()
            ->where([
                'del_flag' => 0,
                    'type' => [1,2,3] //1代表新闻,2代表公告，3代表团队
                    ]);
        }
        $pagination = new Pagination([
            'defaultPageSize' => 4,
            'totalCount' => $query->count()
            ]);
        $informations = $query->orderBy('id DESC')
                              ->offset($pagination->offset)
                              ->limit($pagination->limit)
                              ->all();
        return [
        'informations' => $informations,
        'pagination' => $pagination
        ];
    }
}